<?php
	/**
	*Author 雷日锦 362606856@qq.com 
	*控制器自动生成
	*/
	if(!defined("ROOT_PATH")) exit("die Access ");
	class kucunControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
		}
		
		public function onDefault(){
			$where=" status<8";
			$url=APPADMIN."?m=kucun&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" kcid DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=M("kucun")->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$this->smarty->display("kucun/index.html");
		}
		
		public function onAdd(){
			$kcid=get_post("kcid","i");
			$sites=M("sites")->select();
			if($kcid){
				$data=M("kucun")->selectRow(array("where"=>"kcid={$kcid}"));
				$sids=json_decode(base64_decode($data['content']),true);
				 
				if($sites && $sids){
					foreach($sites as $k=>$v){
						 
						if(in_array($v['siteid'],$sids)){
							$v['isselect']=1;
						}else{
							$v['isselect']=0;
						}
						 
						$sites[$k]=$v;
					}
				}
			}
			$this->smarty->assign(array(
				"data"=>$data,
				"sids"=>$sids,
				"sites"=>$sites
			));
			$this->smarty->display("kucun/add.html");
		}
		
		public function onSave(){
			$kcid=get_post("kcid","i");
			$data=M("kucun")->postData();
			$sids=post("sids",'i');
			 
			$data['content']=base64_encode(json_encode($sids));
			$data['siteid']=SITEID;
			if($kcid){
				M("kucun")->update($data,"kcid='$kcid'");
			}else{
				M("kucun")->insert($data);
			}
			$this->goall("保存成功");
		}
		
		public function onStatus(){
			$kcid=get_post('kcid',"i");
			$status=get_post("status","i");
			M("kucun")->update(array("status"=>$status),"kcid=$kcid");
			$this->goall("状态修改成功",0);
		}
		
		public function onDelete(){
			$kcid=get_post('kcid',"i");
			//M("kucun")->delete("kcid=".$kcid);
			M("kucun")->update(array(
				"status"=>8
			),"kcid=".$kcid);
			$this->goall("删除成功",0);
		}
		
		
	}

?>